/**
 * 异步处理接口
 */

import * as type from './type'
// 引入 微页面接口
import HomeApi from 'Api/home'

const actions = {
    // 获取首页信息
    async getIndexInfo({ commit }, value) {
        let result = await HomeApi.GetIndexData(value)

        let action = {
            type: type.MODIFY_INDEX_INFO,
            payload: result.Data
        }

        commit(action)
    },
    // 获取微页面信息
    async getStoreInfo({ commit }, value) {
        let result = await HomeApi.StoreConfig(value)

        // 7.26 追加 微页面获取新商品数据
        result.Data.PageJson.some(item => {
            if (item.type == "product" && item.dataFrom == 1) {
                HomeApi.getAutoSelectProduct({
                    GroupIds: [],
                    Sort: item.sort,
                    ProductNum: item.topNum
                }).then(res => {
                    item.list = res.Data
                })
            } else if (item.type == "product" && item.dataFrom == 2) {
                HomeApi.GetSelectProduct({
                    ProductIds: item.selectId
                }).then(res => {
                    item.list = res.Data
                })
            }
        })
        
        let action = {
            type: type.MODIFY_STORE_INFO,
            payload: result.Data
        }

        commit(action)
    },
}

export default actions